interface Result {
  [key: string]: {
    pv: number;
    uv: number;
  };
}

type IP = string;
type UUID = string;
type PVS = Map<UUID, number>;
type UVS = Map<UUID, Set<IP>>;

/* A helper class to store the data for each event. */
class EventData {
  pvs: PVS = new Map<UUID, number>();
  uvs: UVS = new Map<UUID, Set<IP>>();

  constructor() {}

  addView = (ip: string, { label = "" }) => {
    if (!this.pvs.has(label)) {
      this.pvs.set(label, 0);
    }
    this.pvs.set(label, (this.pvs.get(label) as number) + 1);

    if (!this.uvs.has(label)) {
      this.uvs.set(label, new Set());
    }
    this.uvs.get(label)?.add(ip);
  };

  getResult = () => {
    let res = {} as Result;
    console.log(this.pvs, this.uvs);

    this.pvs.forEach((value, key) => {
      res[key] = {
        pv: value,
        uv: this.uvs.get(key)?.size ?? 0,
      };
    });
    return res;
  };
}

export default EventData;
